package cenas;

import org.anddev.andengine.audio.sound.SoundManager;
import org.anddev.andengine.engine.handler.IUpdateHandler;
import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.input.touch.TouchEvent;
import org.anddev.andengine.opengl.texture.TextureManager;
import org.anddev.andengine.opengl.texture.TextureOptions;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.anddev.andengine.opengl.texture.region.TextureRegion;

import pi.beta.GerenciamentoDeCenasEEntrada;
import android.content.Context;
import assets.Botao;

public class EscolhaDeNiveis extends Scene {
	public int largura;
	public int altura;
	
	Context contexto;
	TextureManager tm;
	GerenciamentoDeCenasEEntrada trocaDeCenas;
	
	private BitmapTextureAtlas mapaDeTexturas, mapaDeTexturas2;
	private TextureRegion regiaoDaTextura, regiaoDaTextura2;

	public EscolhaDeNiveis(GerenciamentoDeCenasEEntrada trocaDeCenas, Context contexto, int largura, int altura, TextureManager tm, SoundManager sm){
		this.contexto = contexto;
		this.trocaDeCenas = trocaDeCenas;
		this.tm = tm;
		mapaDeTexturas = new BitmapTextureAtlas(1024, 512, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
		mapaDeTexturas2 = new BitmapTextureAtlas(1024, 512, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
		BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
		regiaoDaTextura = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mapaDeTexturas, contexto, "Cenario.png", 0, 0);
		regiaoDaTextura2 = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mapaDeTexturas2, contexto, "Escolha de niveis.png", 0, 0);
		tm.loadTexture(mapaDeTexturas);
		tm.loadTexture(mapaDeTexturas2);
		Sprite cenario = new Sprite(0, 0, regiaoDaTextura);
		Sprite logotipo = new Sprite(0, 50, regiaoDaTextura2);
		attachChild(cenario);
		attachChild(logotipo);
	}
	
	@Override
	public boolean onSceneTouchEvent(TouchEvent toque) {
		//return super.onSceneTouchEvent(pSceneTouchEvent);

		if (toque.getAction() == TouchEvent.ACTION_DOWN) {
			if(toque.getX() > 50 && toque.getY() > 100 && toque.getX() < 250 && toque.getY() < 400) {
				trocaDeCenas.inicializaNivel("Nivel 1.tmx");
			}
			if(toque.getX() > 300 && toque.getY() > 100 && toque.getX() < 500 && toque.getY() < 400) {
				trocaDeCenas.inicializaNivel("Nivel 2.tmx");
			}
		}
		return false;
	}
}
